<template>
	<view class="index">
		<template v-if="ShiFou_DengLu">
			<template v-if="JSON.stringify(Api_BianJiQi_PeiZhi) != '{}'">
				<template v-if="LeiXing == 'ChuangJian'">
					<view
						v-if="DangQian_CaoGao_ShuLiang > 1"
						class="CaoGaoTiShi"
						@click="DianJi_DaKai_CaoGao_LieBiao">
						<text>您有 {{DangQian_CaoGao_ShuLiang}} 条未发布的草稿</text>
						<view>点我查看</view>
					</view>
				</template>
				<template v-if="LeiXing == 'GengXin'">
					<view
						v-if="DangQian_CaoGao_ShuLiang"
						class="CaoGaoTiShi"
						@click="DianJi_DaKai_CaoGao_LieBiao">
						<text>您有 {{DangQian_CaoGao_ShuLiang}} 条未发布的草稿</text>
						<view>点我查看</view>
					</view>
				</template>
				<view
					v-if="Api_BianJiQi_PeiZhi.editor.toolbar.title.status"
					class="DanHang">
					<view>文章标题</view>
					<input
						type="text"
						v-model="BiaoTi_Vmodel"
						:placeholder="Api_BianJiQi_PeiZhi.editor.toolbar.title.required?'必填项':'非必填项'"
						placeholder-style="color: #C0C4CC;">
				</view>
				
				<template v-if="JSON.stringify(QuanJu_BianJiQi_PeiZhi) != '{}'">
					<template v-if="QuanJu_BianJiQi_PeiZhi.JingDian_BianJiQi.KaiQi">
						<view class="NeiRong-BianJi">
							<textarea
								auto-height="true"
								placeholder="请输入内容... Markdown格式"
								placeholder-style="color:#C0C4CC;"
								maxlength="-1"
								:show-confirm-bar="false"
								v-model="NeiRong_Vmodel"></textarea>
						</view>
						<view class="NeiRong-BianJi-CaoZuoAnNiu">
							<view
								v-if="QuanJu_BianJiQi_PeiZhi.JingDian_BianJiQi.GongJu_AnNiu.BiaoTi"
								class="Zi"
								@click="DianJi_BianJiQi_ChaRu_TongYong('BiaoTi')">
								<text>H</text>
							</view>
							<view
								v-if="QuanJu_BianJiQi_PeiZhi.JingDian_BianJiQi.GongJu_AnNiu.JiaCu"
								class="Zi"
								@click="DianJi_BianJiQi_ChaRu_TongYong('JiaCu')">
								<text style="font-weight: bold;">Aa</text>
							</view>
							<view
								v-if="QuanJu_BianJiQi_PeiZhi.JingDian_BianJiQi.GongJu_AnNiu.XieTi"
								class="Zi"
								@click="DianJi_BianJiQi_ChaRu_TongYong('XieTi')">
								<text style="font-style: italic;">Aa</text>
							</view>
							<view
								v-if="QuanJu_BianJiQi_PeiZhi.JingDian_BianJiQi.GongJu_AnNiu.ShanChuXian"
								class="Zi"
								@click="DianJi_BianJiQi_ChaRu_TongYong('ShanChu')">
								<text style="text-decoration:line-through;">Aa</text>
							</view>
							<view
								v-if="QuanJu_BianJiQi_PeiZhi.JingDian_BianJiQi.GongJu_AnNiu.XiaHuaXian"
								class="Zi"
								@click="DianJi_BianJiQi_ChaRu_TongYong('XiaHuaXian')">
								<text style="text-decoration: underline;">Aa</text>
							</view>
							<view
								v-if="QuanJu_BianJiQi_PeiZhi.JingDian_BianJiQi.GongJu_AnNiu.ZiTiYanSe"
								class="Zi"
								@click="DianJi_BianJiQi_ChaRu_TongYong('YanSe')">
								<text style="color: #F56C6C;">Aa</text>
							</view>
							<view
								v-if="QuanJu_BianJiQi_PeiZhi.JingDian_BianJiQi.GongJu_AnNiu.BiaoQing"
								class="Zi"
								@click="$_TiaoZhuan('_Z_GongYong/BiaoQing_LieBiao')">
								<text style="font-size: 22rpx;">😀</text>
							</view>
							<view
								v-if="QuanJu_BianJiQi_PeiZhi.JingDian_BianJiQi.GongJu_AnNiu.LianJie"
								class="Zi"
								@click="DianJi_BianJiQi_ChaRu_TongYong('LianJie')">
								<text>链</text>
							</view>
							<view
								v-if="QuanJu_BianJiQi_PeiZhi.JingDian_BianJiQi.GongJu_AnNiu.YinYong"
								class="Zi"
								@click="DianJi_BianJiQi_ChaRu_TongYong('YinYong')">
								<text>引</text>
							</view>
							<view
								v-if="QuanJu_BianJiQi_PeiZhi.JingDian_BianJiQi.GongJu_AnNiu.LieBiao"
								class="Zi"
								@click="DianJi_BianJiQi_ChaRu_TongYong('LieBiao')">
								<text>列</text>
							</view>
							<view
								v-if="QuanJu_BianJiQi_PeiZhi.JingDian_BianJiQi.GongJu_AnNiu.DaiMa"
								class="Zi"
								@click="DianJi_BianJiQi_ChaRu_TongYong('DaiMa')">
								<text>代</text>
							</view>
						</view>
					</template>
				</template>
			
			
			
			
				<scroll-view
					v-if="Api_BianJiQi_PeiZhi.editor.toolbar.hashtag.status"
					scroll-x="true"
					class="ChaRu-AnNiu">
					<view class="AnNiu" @click="$_TiaoZhuan('_Z_GongYong/HuaTi_LieBiao')">#话题</view>
					<text
						@click="DianJi_ChaRu_HuaTi(item)"
						v-for="item in QuanJu_HuaTi_TuiJian">{{item}}</text>
				</scroll-view>
				
				<scroll-view
					v-if="Api_BianJiQi_PeiZhi.editor.toolbar.mention"
					scroll-x="true"
					class="ChaRu-AnNiu">
					<view class="AnNiu" style="background: #409EFF;" @click="$_TiaoZhuan('_Z_GongYong/AiTe_LieBiao')">@艾特</view>
					<text
						@click="DianJi_ChaRu_YongHu(item.YongHuMing)"
						v-for="item in QuanJu_YongHu_TuiJian">
						{{item.NiCheng}}<text v-if="item.MiaoShu">[{{item.MiaoShu}}]</text>
					</text>
				</scroll-view>
				<view
					v-if="Api_BianJiQi_PeiZhi.editor.toolbar.image.status"
					class="FuJian-ShangChuan FuJian-ShangChuan-TuPian">
					<view class="_Zuo">上传图片</view>
					<view class="_You">
						<view
							v-if="FuJian_TuPian_LieBiao && FuJian_TuPian_LieBiao.length != Api_BianJiQi_PeiZhi.editor.toolbar.image.uploadNumber"
							class="XunHuan JiaHao"
							@click="DianJi_ShangChuan('TuPian')">
							<text class="iconfont icon-xiangji"></text>
						</view>
						<view
							v-for="item in FuJian_TuPian_LieBiao"
							class="XunHuan TuPianYuLan">
							<text class="iconfont icon-close-bold" @click="DianJi_ShanChu_FuJian('TuPian',item.fid)"></text>
							<view
								@longpress="ChangAn_TuPian_ChaRu_ZhengWen(item.fid)"
								@click="$_TiaoZhuan('_Z_GongYong/TuPian_YuLan?url=' + item.imageBigUrl)">
								<image :src="item.imageRatioUrl" mode="widthFix"></image>
							</view>
						</view>
					</view>
				</view>
				
				<view
					v-if="Api_BianJiQi_PeiZhi.editor.toolbar.video.status"
					class="FuJian-ShangChuan FuJian-ShangChuan-TuPian">
					<view class="_Zuo">上传视频</view>
					<view class="_You">
						<view
							v-if="FuJian_ShiPin_LieBiao && FuJian_ShiPin_LieBiao.length != Api_BianJiQi_PeiZhi.editor.toolbar.video.uploadNumber"
							class="XunHuan JiaHao"
							@click="DianJi_ShangChuan('ShiPin')">
							<text class="iconfont icon-zhibo"></text>
						</view>
						<view
							v-for="item in FuJian_ShiPin_LieBiao"
							class="XunHuan TuPianYuLan">
							<text class="iconfont icon-close-bold" @click="DianJi_ShanChu_FuJian('ShiPin',item.fid)"></text>
							<view
								@click="$_TiaoZhuan('_Z_GongYong/ShiPin_YuLan?url='+item.videoUrl)">
								<image :src="item.videoCoverUrl" mode="widthFix"></image>
							</view>
						</view>
					</view>
				</view>
				<!-- #ifndef H5 -->
				<view
					v-if="Api_BianJiQi_PeiZhi.editor.toolbar.audio.status"
					class="FuJian-ShangChuan FuJian-ShangChuan-LuYin">
					<view class="_Zuo">录音</view>
					<view class="_You">
						<view class="Box">
							<!-- 录制、停止 -->
							<view
								v-if="FuJian_YinPin_LieBiao && FuJian_YinPin_LieBiao.length != Api_BianJiQi_PeiZhi.editor.toolbar.audio.uploadNumber"
								class="XunHuan"
								@click="DianJi_LuYin_CaoZuo('LuZhi')">
								<view
									:style="LuYin.LuZhi_ZhuangTai=='录制'?'录制':'border: 1rpx solid #409EFF;'"
									class="XunHuan-Shang">
									<text
										:style="LuYin.LuZhi_ZhuangTai=='录制'?'录制':'color: #409EFF;'"
										:class="LuYin.LuZhi_ZhuangTai=='录制'?'iconfont icon-yuyin':'iconfont icon-lujing'"
									></text>
									<view
										:style="LuYin.LuZhi_ZhuangTai=='录制'?'录制':'color: #409EFF;'">
										{{LuYin.LuZhi_ZhuangTai}}
									</view>
								</view>
								<view
									:style="LuYin.LuZhi_ZhuangTai=='录制'?'录制':'color: #409EFF;'"
									class="XunHuan-Xia">
									{{
										LuYin.LuZhi_ZhuangTai_QiTa == '未录制' ?
										'最长'+Api_BianJiQi_PeiZhi.editor.toolbar.audio.maxTime+'秒':
										LuYin.LuZhi_ZhuangTai_QiTa+'秒'
									}}
								</view>
							</view>
							<view class="Box-You">
								<template v-for="item in FuJian_YinPin_LieBiao">
									<view class="BoFangQi">
										<YouRan-UI-YinPin
											Css="width:350rpx;"
											:Url="item.audioUrl"></YouRan-UI-YinPin>
									</view>
									<view
										@click="DianJi_ShanChu_FuJian('YinPin',item.fid)"
										class="ShanChu">
										<text class="iconfont icon-shibai"></text>
									</view>
								</template>
							</view>
						</view>
					</view>
				</view>
				<!-- #endif -->
				<view class="NeiRong-XiaoZu" v-if="Api_BianJiQi_PeiZhi.editor.features.group.status">
					<view class="ShiFou-BiXuan">
						{{
							Api_BianJiQi_PeiZhi.editor.features.group.required ? '内容小组 - 必选' : '内容小组 - 非必选'
						}}
					</view>
					<template v-if="XiaoZu_LieBiao.length">
						<radio-group @change="DanXuan_XiaoZu_FenLei">
							<view class="XunHuan" v-for="item in XiaoZu_LieBiao">
								<view class="YiJi">{{item.gname}}</view>
								<view class="ErJi">
									<label v-for="item_a in item.groups">
										<radio :checked="postGid == item_a.gid ?true:false" :value="item_a.gid" />
										<view class="ErJi-You">
											<view class="ErJi-You-Tu">
												<image :src="item_a.cover" mode="widthFix"></image>
											</view>
											<view class="ErJi-You-Cheng">{{item_a.gname}}</view>
											<text v-if="!item_a.publishRule.allowPost">[无权]</text>
										</view>
									</label>
								</view>
							</view>
						</radio-group>
					</template>
					<template v-else>
						<YouRan-UI-JiaZaiZhong LeiXing="JuBu"></YouRan-UI-JiaZaiZhong>
					</template>
				</view>
				<view style="display: flex;align-items: center;justify-content: center;padding: 25rpx 0;">
					<view
						class="YouRan-UI-AnNiu-1 Flex"
						style="width: 200rpx;background: #F56C6C;color: #FFF;margin: 0 25rpx 0 0;"
						@click="DianJi_ZhiJie_FaBu">直接发布</view>
					<view
						class="YouRan-UI-AnNiu-1 Flex"
						style="width: 200rpx;background: #606266;color: #FFF;"
						@click="DianJi_BaoCun_CaoGao">保存草稿</view>
				</view>
			</template>
			<template v-if="JSON.stringify(Api_BianJiQi_PeiZhi) == '{}'">
				<YouRan-UI-JiaZaiZhong LeiXing="QuanPing"></YouRan-UI-JiaZaiZhong>
			</template>
		</template>
		<template v-else>
			<view style="width: 100%;height: 100vh;display: flex;align-items: center;justify-content: center;" class="H2 H2-Line Zt-ZhanWeiSe">未登录，请登录</view>
		</template>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				ShiFou_DengLu:false,//-------------------- 判断用户是否登陆
				BiaoTi_Vmodel:"",//----------------------- 标题
				NeiRong_Vmodel:"",//---------------------- 内容
				Api_BianJiQi_PeiZhi:{},//----------------- 请求编辑器配置
				LeiXing:"",//----------------------------- 本页配置类型，是创建还是更新
				CaoGao_ID:"",//--------------------------- 草稿ID
				postGid:"",//----------------------------- 小组ID
				XiaoZu_LieBiao:[],//---------------------- 小组列表
				FuJian_TuPian_LieBiao:[],//--------------- 附件列表，图片
				FuJian_ShiPin_LieBiao:[],//--------------- 附件列表，视频
				FuJian_YinPin_LieBiao:[],//--------------- 附件列表，音频
				DangQian_CaoGao_ShuLiang:0,//------------- 当前草稿数量
				
				LuYin:{
					LuZhi_ZhuangTai:"录制",
					LuZhi_ZhuangTai_QiTa:"未录制"
				},
				
				QuanJu_BianJiQi_PeiZhi:{},
				QuanJu_HuaTi_TuiJian:[],
				QuanJu_YongHu_TuiJian:[]
			}
		},
		onShow() {
			uni.getStorage({
				key: 'XuanZhong_BiaoQing',
				success: (res) => {
					this.NeiRong_Vmodel += res.data;
					uni.removeStorage({ key: 'XuanZhong_BiaoQing' });
				}
			});
			uni.getStorage({
				key: 'XuanZhong_AiTe',
				success: (res) => {
					this.NeiRong_Vmodel += ' @'+res.data+' ';
					uni.removeStorage({ key: 'XuanZhong_AiTe' });
				}
			});
			uni.getStorage({
				key: 'XuanZhong_HuaTi',
				success: (res) => {
					if(this.Api_BianJiQi_PeiZhi.editor.toolbar.hashtag.showMode == 1){
						this.NeiRong_Vmodel += ' #'+res.data+' ';
						uni.removeStorage({ key: 'XuanZhong_HuaTi' });
					}else{
						this.NeiRong_Vmodel += ' #'+res.data+'# ';
						uni.removeStorage({ key: 'XuanZhong_HuaTi' });
					}
					uni.removeStorage({ key: 'XuanZhong_HuaTi' });
				}
			});
		},
		onLoad(e) {
			if(uni.getStorageSync('ZhangHaoXinXi') && uni.getStorageSync('YongHuXinXi')){
				this.ShiFou_DengLu = true;
				if(e.LeiXing == "ChuangJian"){
					this.LeiXing = "ChuangJian";
					uni.setNavigationBarTitle({ title:"创建草稿" });
					this.QingQiu_ChuangJian_CaoGao();
				}
				if(e.LeiXing == "GengXin"){
					this.LeiXing = "GengXin";
					this.CaoGao_ID = e.id;
					uni.setNavigationBarTitle({ title:"更新草稿" });
					// 请求，草稿，详情
					this.QingQiu_CaoGao_XiangQing();
				}
				// 请求，全局，配置
				this.QingQiu_QuanJu_PeiZhi();
			}
		},
		methods: {
			QingQiu_QuanJu_PeiZhi(){
				uni.request({
					url:this.$_PeiZhi_WenJian() + "QuanJu.json",
					method:'GET',
					success: (res) => {
						this.QuanJu_BianJiQi_PeiZhi = res.data.Bian_Ji_Qi;
						this.QuanJu_HuaTi_TuiJian = res.data.HuaTi_TuiJian;
						this.QuanJu_YongHu_TuiJian = res.data.YongHu_TuiJian;
						// 请求，编辑器，配置，API
						this.QingQiu_BianJiQi_PeiZhi();
					}
				})
			},
			// 获取草稿数量
			QingQiu_HuoQu_CaoGao_ShuLiang(){
				uni.request({
					url:this.$_URL() + "/api/v2/editor/post/drafts",
					method:'GET',
					header:this.$_Fresns_Header(),
					success: (res) => {
						this.DangQian_CaoGao_ShuLiang = res.data.data.paginate.total;
					}
				})
			},
			// 点击，打开，草稿，列表
			DianJi_DaKai_CaoGao_LieBiao(){
				uni.redirectTo({
					url:"/pages/_Z_GongYong/CaoGao_LieBiao"
				})
			},
			// 请求，创建，草稿
			QingQiu_ChuangJian_CaoGao(){
				uni.request({
					url:this.$_URL() + "/api/v2/editor/post/create",
					method:"POST",
					header:this.$_Fresns_Header(),
					data:{
						"createType":2
					},
					success: (res) => {
						this.CaoGao_ID = res.data.data.detail.id;
					}
				})
			},
			// 请求，草稿，详情
			QingQiu_CaoGao_XiangQing(){
				uni.request({
					url:this.$_URL() + "/api/v2/editor/post/" + this.CaoGao_ID,
					method:'GET',
					header:this.$_Fresns_Header(),
					success: (res) => {
						this.BiaoTi_Vmodel = res.data.data.detail.title;
						this.NeiRong_Vmodel = res.data.data.detail.content;
						this.FuJian_TuPian_LieBiao = res.data.data.detail.files.images;
						this.FuJian_ShiPin_LieBiao = res.data.data.detail.files.videos;
						this.FuJian_YinPin_LieBiao = res.data.data.detail.files.audios;
						if(res.data.data.detail.group){
							this.postGid = res.data.data.detail.group[0].gid;
						}
					}
				})
			},
			// 请求，编辑器，配置
			QingQiu_BianJiQi_PeiZhi(){
				uni.request({
					url:this.$_URL() + "/api/v2/editor/post/config",
					method:'GET',
					header:this.$_Fresns_Header(),
					success: (res) => {
						this.Api_BianJiQi_PeiZhi = res.data.data;
						// 请求，小组，列表
						this.QingQiu_XiaoZu_LieBiao();
					}
				})
			},
			// 点击，上传
			DianJi_ShangChuan(e){
				if(e == 'TuPian'){
					let Shu = this.Api_BianJiQi_PeiZhi.editor.toolbar.image.uploadNumber;
					uni.chooseImage({
						count:parseInt(Shu) ? parseInt(Shu) : 1,
						success: (res) => {
							this.DianJi_ShangChuan_TuPian(res.tempFiles)
						}
					})
				}
				if(e == 'ShiPin'){
					uni.chooseVideo({
						maxDuration:parseInt(this.Api_BianJiQi_PeiZhi.editor.toolbar.video.maxTime),
						success: (res) => {
							this.DianJi_ShangChuan_ShiPin(res.tempFilePath)
						}
					})
				}
			},
			// 点击，上传，视频
			DianJi_ShangChuan_ShiPin(e){
				const _this = this;
				uni.showLoading({ title: "上传中" });
				uni.uploadFile({
					url: _this.$_URL() + "/api/v2/common/upload-file",
					filePath: e,
					name: "file",
					header: _this.$_Fresns_Header(),
					formData:{
						"tableName":"post_logs",
						"tableColumn":"id",
						"type":"video",
						"uploadMode":"file",
						"tableId":_this.CaoGao_ID
					},
					success(res) {
						if(JSON.parse(res.data).code == 0){
							uni.hideLoading();
							_this.QingQiu_CaoGao_XiangQing_FuJian_ShiPin();
						}else{
							uni.hideLoading();
							uni.showToast({
								title:res.data.message,
								icon:"none",
								duration:1000
							});
						}
					}
				})
			},
			// 点击，上传，图片
			DianJi_ShangChuan_TuPian(params){
				uni.showLoading({ title: "上传中" });
				return new Promise((presolve, preject) => {
					let uploads = [];
					(params).forEach((item, i) => {
						uploads[i] = new Promise((resolve) => {
							uni.uploadFile({
								url: this.$_URL() + "/api/v2/common/upload-file",
								filePath: item.path,
								name: "file",
								header: this.$_Fresns_Header(),
								formData:{
									"tableName":"post_logs",
									"tableColumn":"id",
									"type":"image",
									"uploadMode":"file",
									"tableId":this.CaoGao_ID
								},
								success(res) {
									if(JSON.parse(res.data).code == 0){
										resolve()
									}else{
										uni.hideLoading();
										resolve()
									}
								},
								fail(err) {
									
								}
							})
						})
					})
					Promise.all(uploads).then(res => {
						//图片上传完成
						presolve(res)
						uni.hideLoading();
						this.QingQiu_CaoGao_XiangQing_FuJian_TuPian();
					}).catch(err => {
						preject(err)
						uni.showToast({
							title: '上传失败请重试',
							icon: 'none'
						})
					})
				})
			},
			// 点击，删除，附件
			DianJi_ShanChu_FuJian(LeiXing,fid){
				uni.showModal({
					title: "提示",
					content: "是否要删除本附件？",
					success: (res) => {
						if(res.confirm) {
							uni.showLoading({ title: "图片删除中" });
							uni.request({
								url:this.$_URL() + "/api/v2/editor/post/" + this.CaoGao_ID,
								method:'PUT',
								header:this.$_Fresns_Header(),
								data:{
									"deleteFile":fid
								},
								success: (res_) => {
									uni.hideLoading();
									if(res_.data.code == 0){
										if(LeiXing == 'TuPian'){
											this.QingQiu_CaoGao_XiangQing_FuJian_TuPian();
										}
										if(LeiXing == 'ShiPin'){
											this.QingQiu_CaoGao_XiangQing_FuJian_ShiPin();
										}
										if(LeiXing == 'YinPin'){
											this.QingQiu_CaoGao_XiangQing_FuJian_YinPin();
										}
									}else{
										uni.showToast({
											title:res_.data.message,
											icon:"none",
											duration:1000
										});
									}
								}
							})
						}
					}
				});
			},
			// 请求，草稿，详情，附件，图片
			QingQiu_CaoGao_XiangQing_FuJian_TuPian(){
				uni.request({
					url:this.$_URL() + "/api/v2/editor/post/" + this.CaoGao_ID,
					method:'GET',
					header:this.$_Fresns_Header(),
					success: (res) => {
						this.FuJian_TuPian_LieBiao = res.data.data.detail.files.images;
					}
				})
			},
			// 请求，草稿，详情，附件，视频
			QingQiu_CaoGao_XiangQing_FuJian_ShiPin(){
				uni.request({
					url:this.$_URL() + "/api/v2/editor/post/" + this.CaoGao_ID,
					method:'GET',
					header:this.$_Fresns_Header(),
					success: (res) => {
						this.FuJian_ShiPin_LieBiao = res.data.data.detail.files.videos;
					}
				})
			},
			// 请求，草稿，详情，附件，音频
			QingQiu_CaoGao_XiangQing_FuJian_YinPin(){
				uni.request({
					url:this.$_URL() + "/api/v2/editor/post/" + this.CaoGao_ID,
					method:'GET',
					header:this.$_Fresns_Header(),
					success: (res) => {
						this.FuJian_YinPin_LieBiao = res.data.data.detail.files.audios;
					}
				})
			},
			// 点击，直接，发布
			DianJi_ZhiJie_FaBu(){
				uni.showLoading({ title: "发布中" });
				uni.request({
					url:this.$_URL() + "/api/v2/editor/post/" + this.CaoGao_ID,
					method:'PUT',
					header:this.$_Fresns_Header(),
					data:{
						"postGid":this.postGid,
						"postTitle":this.BiaoTi_Vmodel,
						"content":this.NeiRong_Vmodel,
						"isMarkdown":true
					},
					success: (res) => {
						uni.hideLoading();
						if(res.data.code == 0){
							uni.request({
								url:this.$_URL() + "/api/v2/editor/post/" + this.CaoGao_ID,
								method:'POST',
								header:this.$_Fresns_Header(),
								success: (res_) => {
									if(res_.data.code == 0){
										uni.setStorage({
											key: 'TongZhi_ShangYiYe',
											data: "true",
											success: (res) => {
												uni.switchTab({
													url: "/pages/FaXian/FaXian"
												});
											}
										});
									}else{
										uni.showToast({
											title:res_.data.message,
											icon:"none",
											duration:1000
										});
									}
								}
							})
						}else{
							uni.showToast({
								title:res.data.message,
								icon:"none",
								duration:1000
							});
						}
					}
				})
			},
			// 点击，保存，草稿
			DianJi_BaoCun_CaoGao(){
				uni.showLoading({ title: "草稿保存中" });
				uni.request({
					url:this.$_URL() + "/api/v2/editor/post/" + this.CaoGao_ID,
					method:'PUT',
					header:this.$_Fresns_Header(),
					data:{
						"postGid":this.postGid,
						"postTitle":this.BiaoTi_Vmodel,
						"content":this.NeiRong_Vmodel,
						"isMarkdown":true
					},
					success: (res) => {
						uni.hideLoading();
						if(res.data.code == 0){
							uni.showToast({
								title:"保存成功",
								icon:"none",
								duration:1000
							});
						}else{
							uni.showToast({
								title:res.data.message,
								icon:"none",
								duration:1000
							});
						}
					}
				})
			},
			// 点击，编辑器，插入，通用事件
			DianJi_BianJiQi_ChaRu_TongYong(e){
				if(e == 'BiaoTi'){
					uni.showActionSheet({
						itemList: ['H1','H2','H3','H4','H5','H6'],
						success: (res) => {
							if(res.tapIndex === 0){
								this.NeiRong_Vmodel += `\n# `;
							}
							if(res.tapIndex === 1){
								this.NeiRong_Vmodel += `\n## `;
							}
							if(res.tapIndex === 2){
								this.NeiRong_Vmodel += `\n### `;
							}
							if(res.tapIndex === 3){
								this.NeiRong_Vmodel += `\n#### `;
							}
							if(res.tapIndex === 4){
								this.NeiRong_Vmodel += `\n##### `;
							}
							if(res.tapIndex === 5){
								this.NeiRong_Vmodel += `\n###### `;
							}
						}
					});
				}
				if(e === 'JiaCu'){this.NeiRong_Vmodel += `**加粗内容**`;}
				if(e === 'XieTi'){this.NeiRong_Vmodel += `*斜体内容*`;}
				if(e === 'ShanChu'){this.NeiRong_Vmodel += `~~删除线~~`;}
				if(e === 'XiaHuaXian'){this.NeiRong_Vmodel += `<u>下划线</u>`;}
				if(e === 'LianJie'){this.NeiRong_Vmodel += `[锚文本](https://url)`;}
				if(e === 'YinYong'){this.NeiRong_Vmodel += `\n> `;}
				if(e === 'LieBiao'){this.NeiRong_Vmodel += `\n- `;}
				if(e === 'DaiMa'){this.NeiRong_Vmodel += "\n```" + "\n[代码]\n" + "```\n";}
				if(e === 'YanSe'){
					uni.showActionSheet({
						itemList: ['红色','粉色','蓝色','绿色','黄色','橘黄'],
						success: (res) => {
							if(res.tapIndex === 0){
								this.NeiRong_Vmodel += `<font color="red">文字</font>`;
							}
							if(res.tapIndex === 1){
								this.NeiRong_Vmodel += `<font color="fuchsia">文字</font>`;
							}
							if(res.tapIndex === 2){
								this.NeiRong_Vmodel += `<font color="blue">文字</font>`;
							}
							if(res.tapIndex === 3){
								this.NeiRong_Vmodel += `<font color="lime">文字</font>`;
							}
							if(res.tapIndex === 4){
								this.NeiRong_Vmodel += `<font color="yellow">文字</font>`;
							}
							if(res.tapIndex === 5){
								this.NeiRong_Vmodel += `<font color="orangered">文字</font>`;
							}
						}
					});
				}
				
			},
			// 请求，小组，列表  XiaoZu_LieBiao
			QingQiu_XiaoZu_LieBiao(){
				uni.request({
					url:this.$_URL() + "/api/v2/group/tree",
					method:'GET',
					header:this.$_Fresns_Header(),
					success: (res) => {
						this.XiaoZu_LieBiao = res.data.data;
						// 获取草稿数量
						this.QingQiu_HuoQu_CaoGao_ShuLiang();
					}
				})
			},
			// 单选，小组，分类
			DanXuan_XiaoZu_FenLei(e){
				this.postGid = e.target.value;
			},
			// 点击，录音，操作
			DianJi_LuYin_CaoZuo(e){
				if(e == 'LuZhi'){
					if(this.LuYin.LuZhi_ZhuangTai == '录制'){
						uni.getRecorderManager().start();
						this.LuYin.LuZhi_ZhuangTai = "停止";
						this.LuYin.LuZhi_ZhuangTai_QiTa = 1;
						this.JiShiQi = setInterval(() => {
							this.LuYin.LuZhi_ZhuangTai_QiTa += 1;
							if(this.LuYin.LuZhi_ZhuangTai_QiTa == this.Api_BianJiQi_PeiZhi.editor.toolbar.audio.maxTime-1){
								this.LuYin.LuZhi_ZhuangTai_QiTa = '未录制'
								this.LuYin.LuZhi_ZhuangTai = '录制'
								clearInterval(this.JiShiQi)
								uni.getRecorderManager().stop();
								uni.getRecorderManager().onStop((res) => {
									this.DianJi_LuYin_CaoZuo_ShangChuan(res.tempFilePath)
								});
							}
						}, 1000);
					}else{
						this.LuYin.LuZhi_ZhuangTai_QiTa = '未录制'
						this.LuYin.LuZhi_ZhuangTai = '录制'
						clearInterval(this.JiShiQi)
						uni.getRecorderManager().stop();
						uni.getRecorderManager().onStop((res) => {
							this.DianJi_LuYin_CaoZuo_ShangChuan(res.tempFilePath)
						});
					}
				}
			},
			// 点击，录音，操作，上传
			DianJi_LuYin_CaoZuo_ShangChuan(e){
				const _this = this;
				uni.showLoading({ title: "上传中" });
				uni.uploadFile({
					url: _this.$_URL() + "/api/v2/common/upload-file",
					filePath: e,
					name: "file",
					header: _this.$_Fresns_Header(),
					formData:{
						"tableName":"post_logs",
						"tableColumn":"id",
						"type":"audio",
						"uploadMode":"file",
						"tableId":_this.CaoGao_ID
					},
					success(res) {
						uni.hideLoading();
						if(JSON.parse(res.data).code == 0){
							_this.QingQiu_CaoGao_XiangQing_FuJian_YinPin()
						}else{
							uni.showToast({
								title:JSON.parse(res.data).message,
								icon:"none",
								duration:1000
							});
						}
					}
				})
			},
			DianJi_ChaRu_HuaTi(e){
				if(this.Api_BianJiQi_PeiZhi.editor.toolbar.hashtag.showMode == 1){
					this.NeiRong_Vmodel += ' #'+e+' ';
				}else{
					this.NeiRong_Vmodel += ' #'+e+'# ';
				}
			},
			DianJi_ChaRu_YongHu(e){
				this.NeiRong_Vmodel += ' @'+e+' ';
			},
			ChangAn_TuPian_ChaRu_ZhengWen(e){
				this.NeiRong_Vmodel += `[file:${e}]`;
			},
		},
		onBackPress(e){
			if(e.from == 'backbutton'){
				uni.showLoading({ title: "草稿保存中" });
				uni.request({
					url:this.$_URL() + "/api/v2/editor/post/" + this.CaoGao_ID,
					method:'PUT',
					header:this.$_Fresns_Header(),
					data:{
						"postGid":this.postGid,
						"postTitle":this.BiaoTi_Vmodel,
						"content":this.NeiRong_Vmodel,
						"isMarkdown":true
					},
					success: (res) => {
						uni.hideLoading();
						if(res.data.code == 0){
							return false; // 禁止返回
						}else{
							return true; // 禁止返回
							uni.showToast({
								title:res.data.message,
								icon:"none",
								duration:1000
							});
						}
					}
				})
			}
			// 如果是uni.navigateBack()事件，则直接返回，通常都是发布成功以后调用
			if(e.from == 'navigateBack'){
				clearInterval(this.JiShiQi); // 取消自动保存定时器
				return false;
			}
		},
	}
</script>

<style lang="scss">
.index{
	.DanHang{
		border: 1rpx solid $BianKuangSe;
		margin: 25rpx 25rpx 0 25rpx;
		display: flex;
		align-items: center;
		padding: 1rpx;
		view{
			font-size: 22rpx;
			height: 80rpx;
			padding: 0 25rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			background: $BeiJingSe;
			border-right: 1rpx solid $BianKuangSe;
			color: $ZhanWeiSe;
		}
		input{
			flex: 1;
			height: 80rpx;
			text-align: center;
			font-size: 28rpx;
		}
	}
	.NeiRong-BianJi{
		border: 1rpx solid $BianKuangSe;
		margin: 25rpx 25rpx 0 25rpx;
		textarea{
			font-size: 28rpx;
			width:calc(100% - 50rpx);
			height: 400rpx;
			display: block;
			padding: 20rpx 25rpx;
			line-height: 45rpx;
			overflow: hidden;
		}
	}
	.NeiRong-BianJi-CaoZuoAnNiu{
		border: 1rpx solid $BianKuangSe;
		margin: 0 25rpx 0 25rpx;
		display: flex;
		background: $BeiJingSe;
		border-top: 0;
		.Zi{
			border-right: 1rpx solid $BianKuangSe;
			line-height: 18rpx;
			padding: 15rpx 20rpx;
			text{
				display: block;
				font-size: 18rpx;
				line-height: 18rpx;
			}
		}
	}
	.FuJian-ShangChuan{
		border: 1rpx solid $BianKuangSe;
		margin: 25rpx 25rpx 0 25rpx;
		display: flex;
		padding: 1rpx;
		._Zuo{
			flex-shrink: 0;
			font-size: 22rpx;
			padding: 0 25rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			background: $BeiJingSe;
			border-right: 1rpx solid $BianKuangSe;
			color: $ZhanWeiSe;
		}
		._You{
			display: flex;
			flex-wrap: wrap;
			padding: 0 0 25rpx 0;
		}
	}
	.FuJian-ShangChuan-TuPian{
		._You{
			display: flex;
			flex-wrap: wrap;
			padding: 0 0 25rpx 0;
			.XunHuan{
				margin: 25rpx 0 0 25rpx;
				width: 110rpx;
				height: 110rpx;
				overflow: hidden;
				border: 1rpx solid $BianKuangSe;
			}
			.JiaHao{
				display: flex;
				align-items: center;
				justify-content: center;
				text{
					color: $ZhanWeiSe;
					font-size: 50rpx;
				}
			}
			.TuPianYuLan{
				position: relative;
				background: $BeiJingSe;
				view{
					background: $BeiJingSe;
					position: absolute;
					z-index: 1;
					top: 0;
					left: 0;
					width: 110rpx;
					height: 110rpx;
					image{
						display: block;
						width: 100%;
					}
				}
				.icon-close-bold{
					position: absolute;
					z-index: 2;
					top: 0;
					right: 0;
					width: 30rpx;
					height: 30rpx;
					display: flex;
					align-items: center;
					justify-content: center;
					background: #F56C6C;
					color: #FFF;
					font-size: 18rpx;
				}
			}
		}
	}
	.FuJian-ShangChuan-LuYin{
		._You{
			display: flex;
			flex-wrap: wrap;
			padding: 0 0 25rpx 0;
			.Box{
				display: flex;
				.XunHuan{
					.XunHuan-Shang{
						margin: 25rpx 0 0 25rpx;
						width: 120rpx;
						height: 90rpx;
						overflow: hidden;
						border: 1rpx solid $BianKuangSe;
						border-radius: 15rpx;
						display: flex;
						align-items:center;
						justify-content:center;
						flex-flow: column;
						text{
							font-size: 35rpx;
							line-height: 35rpx;
							color: $ZhanWeiSe;
							margin: 0 0 5rpx 0;
						}
						view{
							font-size: 16rpx;
							line-height: 16rpx;
							color: $ZhanWeiSe;
						}
					}
					.XunHuan-Xia{
						display: flex;
						align-items: center;
						justify-content: center;
						font-size: 16rpx;
						line-height: 16rpx;
						color: $ZhanWeiSe;
						margin: 15rpx 0 0 25rpx;
						width: 120rpx;
					}
				}
				.Box-You{
					padding: 0 0 0 25rpx;
					display: flex;
					align-items: center;
					flex-wrap: wrap;
					.BoFangQi{
						margin-top: 25rpx;
					}
					.ShanChu{
						margin: 25rpx 0 0 10rpx;
						text{
							font-size: 60rpx;
							line-height: 60rpx;
							color: $ZhanWeiSe;
						}
					}
				}
			}
			
		}
	}
	.NeiRong-XiaoZu{
		margin: 10rpx 25rpx 0 25rpx;
		.ShiFou-BiXuan{
			font-size: 22rpx;
			line-height: 22rpx;
			color: #FFF;
			background: #409EFF;
			display: inline-flex;
			padding: 15rpx 20rpx;
			border-radius: 100rpx;
			margin-top: 15rpx;
		}
		.XunHuan{
			display: flex;
			margin-top: 25rpx;
			border-bottom: 1rpx solid $BeiJingSe;
			.YiJi{
				font-size: 28rpx;
				line-height: 28rpx;
				margin-right: 25rpx;
				color: $ZhanWeiSe;
			}
			.ErJi{
				label{
					height: auto;
					display: flex;
					align-items: flex-start;
					padding-bottom: 15rpx;
					radio{
						margin: -15rpx -5rpx 0 -10rpx;
						transform: scale(0.5);
						padding: 0;
						height: auto;
					}
					.ErJi-You{
						display: flex;
						align-items: center;
						.ErJi-You-Tu{
							width: 28rpx;
							height: 28rpx;
							overflow: hidden;
							border-radius: 100%;
							margin-right: 15rpx;
						}
						.ErJi-You-Cheng{
							font-size: 28rpx;
							line-height: 28rpx;
						}
						text{
							padding-left: 15rpx;
							font-size: 18rpx;
							line-height: 18rpx;
							color: $ZhanWeiSe;
						}
					}
				}
			}
		}
	}
	.CaoGaoTiShi{
		background: $HongSe;
		margin: 25rpx 25rpx 0 25rpx;
		line-height: 22rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		padding: 25rpx 0;
		border-radius: 100rpx;
		text{
			font-size: 22rpx;
			line-height: 22rpx;
			color: #FFF;
		}
		view{
			font-size: 18rpx;
			line-height: 18rpx;
			border: .5rpx solid #FFF;
			border-radius: 10rpx;
			padding: 10rpx;
			margin: 0 0 0 15rpx;
			color: #FFF;
		}
	}
	.ChaRu-AnNiu{
		width: 700rpx;
		background: $BeiJingSe;
		margin: 25rpx 25rpx 0 25rpx;
		border: 1rpx solid $BianKuangSe;
		white-space: nowrap;
		display: flex;
		align-items: center;
		padding: 10rpx 0 15rpx 0;
		view{
			display: inline;
			font-size: 22rpx;
			line-height: 22rpx;
		}
		.AnNiu{
			color: #FFF;
			background: $HongSe;
			border-radius: 100rpx;
			padding: 5rpx 15rpx;
			margin:0 25rpx;
		}
		text{
			font-size: 22rpx;
			line-height: 22rpx;
			padding: 0 25rpx 0 0;
			text{
				padding: 0 0 0 5rpx;
				font-size: 12rpx;
				line-height: 12rpx;
				color: $ZhanWeiSe;
			}
		}
	}
}
.FenLei-XuanXiangKa {
	width: 750rpx;
	height: 200rpx;
	view{
		width: 100%;
		height: 80rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 28rpx;
		line-height: 28rpx;
	}
}
</style>